<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__static/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="__static/css/public.css" media="all">
    <script typet="text/javascript" src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" lay-filter="from1">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">物品名称</label>
                            <div class="layui-input-inline">
                                <input type="text" id="username" name="username" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="button" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon" onclick="get_ss()"></i> 搜 索
                            </button>
                        </div>
                    </div>
                </form>
            </div>
            <table class="layui-hide" id="currentTableId1" lay-filter="currentTableFilter"></table>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button style="display: none;" class="layui-btn layui-btn-normal layui-btn-sm data-add-btn"
                        lay-event="add"> 添加
                </button>
                <button style="display: none;" class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn"
                        lay-event="delete"> 删除
                </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
<script src="__static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    var form, table;
    layui.use(['table'], function () {
        table = layui.table, form = layui.form;
        //用户数据列表
        table.render({
            elem: '#currentTableId1',//输入页面输入框
            url: '{:url("/Manage/bomselect/t/json")}',
            method: 'post',//模糊查询姓名乱码解决
            toolbar: '#toolbar', //开启头部工具栏，并为其绑定左侧模板
            id: 'userTable',
            page: true,
            skin: 'line',
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'bomid', width: 120, title: '物品编号'},
                {field: 'bomname', width: 120, title: '物品名称'},
                {field: 'sort_name', width: 120, title: '物品分类'},
                {field: 'bomcount', width: 120, title: '物品库存'},
                {field: 'bomlogintime', width: 180, title: '物品购买时间'},
                {field: 'bomupdatetime', width: 180, title: '物品库存更改时间'},
                {field: 'remark', width: 400, title: '备注'},
                {title: '操作', minWidth: 100, toolbar: '#currentTableBar', align: "center"}
            ]]
        });
        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加用户',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '__static/page/table/add.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/manage/bomedit/bomid/' + data.bomid,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                var confirm = layer.confirm('确定删除员工信息吗?', {
                    yes: function (id) {
                        var url = '/manage/bom_del/bomid/' + data.bomid;
                        $.get(url, function (d) {
                            if (d.msg != 0) {
                                layer.msg('删除成功!', {
                                    time: 500
                                });
                            } else {
                                layer.msg('删除失败，请重试!', {
                                    time: 500
                                });
                            }
                            setTimeout('window.location.reload()', 500);
                        });
                        layer.close(confirm);
                    }
                });
            }
        });
        table.on('from(data-search-btn)', function (obj) {
            var data = obj.data;

        });

    });

    //重载数据表
    //数据刷新时，触发
    function get_s(msg) {
        table.reload('testReload', {
            url: '{:url("Manage/bomselect/")}',
            //where: {} //设定异步数据接口的额外参数
            //,height: 300
        });
        layer.msg(msg, {icon: 6});
    }

    function get_ss() {
        var bomname = $("#username").val();
        // var bomclassify = $("#department").val();

        table.reload('testReload', {
            url: '{:url("Manage/bomselect/")}',
            where: {bomname: bomname} //设定异步数据接口的额外参数
        });
    }
</script>
</body>
</html>
